/*
 *  POJ1837: Balance
 */

/*-------- Includes --------*/
#include <iostream>
#include <cstring>

using namespace std;

/*-------- Defines --------*/


/*-------- Types --------*/


/*-------- Global Variables --------*/
int hk[21];
int wt[21];
int dp[21][15001];

/*-------- Function Prototypes --------*/


/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    int C, G;

    // get input
    cin >> C >> G;

    for (int i = 1; i <= C; i++) cin >> hk[i];
    for (int i = 1; i <= G; i++) cin >> wt[i];

    // initialize
    memset(dp, 0, sizeof(dp));
    dp[0][7500] = 1;

    // dynamic programming
    for (int i = 1; i <= G; i++) {
        for (int j = 0; j < 15001; j++) {
            if (dp[i - 1][j]) {
                for (int k = 1; k <= C; k++)
                    dp[i][j + hk[k] * wt[i]] += dp[i - 1][j];
            }
        }
    }

    // print result
    cout << dp[G][7500] << endl;
}

/*-------- Functions --------*/

